export const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api';

export const API_ENDPOINTS = {
  // 认证相关
  AUTH: {
    LOGIN: '/auth/login',
    REGISTER: '/auth/register',
    LOGOUT: '/auth/logout',
    REFRESH_TOKEN: '/auth/refresh-token',
    PROFILE: '/auth/profile',
  },
  
  // 仪表盘
  DASHBOARD: {
    OVERVIEW: '/dashboard/overview',
    STATISTICS: '/dashboard/statistics',
  },

  // 设备管理
  DEVICES: {
    LIST: '/devices',
    DETAIL: (id: string) => `/devices/${id}`,
    CREATE: '/devices',
    UPDATE: (id: string) => `/devices/${id}`,
    DELETE: (id: string) => `/devices/${id}`,
    STATUS: (id: string) => `/devices/${id}/status`,
  },

  // 能源管理
  ENERGY: {
    USAGE: '/energy/usage',
    STATISTICS: '/energy/statistics',
    DEVICES: '/energy/devices',
  },

  // 停车管理
  PARKING: {
    SPACES: '/parking/spaces',
    RECORDS: '/parking/records',
    STATISTICS: '/parking/statistics',
  },

  // 人员管理
  PERSONNEL: {
    LIST: '/personnel',
    DETAIL: (id: string) => `/personnel/${id}`,
    CREATE: '/personnel',
    UPDATE: (id: string) => `/personnel/${id}`,
    DELETE: (id: string) => `/personnel/${id}`,
  },

  // 安防系统
  SECURITY: {
    EVENTS: '/security/events',
    CAMERAS: '/security/cameras',
    ALERTS: '/security/alerts',
  },

  // 通知
  NOTIFICATIONS: {
    LIST: '/notifications',
    MARK_READ: (id: string) => `/notifications/${id}/read`,
    MARK_ALL_READ: '/notifications/read-all',
  },
} as const;

export type ApiEndpoints = typeof API_ENDPOINTS;

// API响应的通用接口
export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  error?: {
    code: string;
    message: string;
  };
}

// 分页响应的通用接口
export interface PaginatedResponse<T> extends ApiResponse {
  data: {
    items: T[];
    total: number;
    page: number;
    pageSize: number;
    totalPages: number;
  };
}

// 通用的查询参数接口
export interface QueryParams {
  page?: number;
  pageSize?: number;
  sortBy?: string;
  sortOrder?: 'asc' | 'desc';
  search?: string;
  [key: string]: any;
}
